package com.briup.ch10;

/**
 * @Author briup-adam
 * @Date 2023/10/26 下午5:31
 * @Description
 **/

public class ThreadGroupTest {
    public static void main(String[] args) {
        Thread thread = Thread.currentThread();
        ThreadGroup group = thread.getThreadGroup();
        System.out.println(group);
        Thread t1 = new Thread();
        ThreadGroup group1 = t1.getThreadGroup();
        System.out.println("group1 = " + group1);

        ThreadGroup group2 = new ThreadGroup("欢天喜地五仙女");
        Thread t2 = new Thread(group2,"马俊辉");
        ThreadGroup group3 = t2.getThreadGroup();
        System.out.println(group3);
        Runnable r=new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <100 ; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        Thread t3 = new Thread(group2, r, "高文武");
        Thread t4 = new Thread(group2, r, "姚文慧");
        Thread t5 = new Thread(group2, r, "托儿索");
        Thread t6 = new Thread(group2, r, "她二姨");
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
        //获取group2  中活跃的线程数
        int count = group2.activeCount();
        System.out.println("count = " + count);
        Thread[] threads = new Thread[count];
        //将活跃线程拿到
        group2.enumerate(threads);
        for (Thread thread1 : threads) {
            System.out.println("active  thread in group2:"+thread1);

        }


    }
}
